package com.caiyi.financial.nirvana.sms.filters;

import com.caiyi.financial.nirvana.sms.enums.ReturnCodeEnum;
import com.caiyi.financial.nirvana.sms.jedis.JedisKey;
import com.caiyi.financial.nirvana.sms.jedis.JedisService;
import com.youyu.common.utils.YyAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

/**
 * 敏感词过滤
 */
public class KeywordFilter implements Filter {

    private Logger logger = LoggerFactory.getLogger(KeywordFilter.class);

    /**
     * 实现Run
     *
     * @param filterChain 过滤链对象
     */
    @Override
    public void run(FilterChain filterChain) {
        Set<String> keywords = JedisService.smembers(JedisKey.SMS_KEYWORD);
        String content = filterChain.getParam().getContent();
        for (String keyword : keywords) {
            YyAssert.isFalse(content.contains(keyword), ReturnCodeEnum.KEYWORD_ERROR);
        }
        filterChain.doFilter();
    }
}
